//
//  AWDiscussionNoticeMessage.m
//  AtWork2
//
//  Created by lucas on 15/6/29.
//  Copyright (c) 2015年 Foreveross. All rights reserved.
//

#import "AWDiscussionNoticeMessage.h"

static inline AWDiscussionNoticeMessageOperation parseDiscussionNoticeMessageOperation(NSString *operation) {
    if ([operation.uppercaseString isEqualToString:AWMessageKOperationCreated]) {
        return AWDiscussionNoticeMessageOperationCreated;
    }
    if ([operation.uppercaseString isEqualToString:AWMessageKOperationDismissed]) {
        return AWDiscussionNoticeMessageOperationDismissed;
    }
    if ([operation.uppercaseString isEqualToString:AWMessageKOperationProfileChanged]) {
        return AWDiscussionNoticeMessageOperationProfileChanged;
    }
    if ([operation.uppercaseString isEqualToString:AWMessageKOperationSettingChanged]) {
        return AWDiscussionNoticeMessageOperationSettingChanged;
    }
    if ([operation.uppercaseString isEqualToString:AWMessageKOperationMemberJoined]) {
        return AWDiscussionNoticeMessageOperationMemberJoined;
    }
    if ([operation.uppercaseString isEqualToString:AWMessageKOperationMemberKicked]) {
        return AWDiscussionNoticeMessageOperationMemberKicked;
    }
    if ([operation.uppercaseString isEqualToString:AWMessageKOperationMemberLeaved]) {
        return AWDiscussionNoticeMessageOperationMemberLeaved;
    }
    if ([operation.uppercaseString isEqualToString:AWMessageKOperationNameChanged]) {
        return AWDiscussionNoticeMessageOperationNameChanged;
    }
    return NSNotFound;
}

@implementation AWDiscussionNoticeMessage

#pragma mark - Getter Setter Methods

- (AWDiscussionNoticeMessageOperation)operation {
    return parseDiscussionNoticeMessageOperation([self bodyValueForKey:AWMessageKOperation]);
}

- (NSString *)noticeOperator {
    return [self bodyValueForKey:AWMessageKOperator];
}

- (NSArray *)members {
    return [self bodyValueForKey:AWMessageKMembers];
}

- (NSDictionary *)moreInfo {
    return [self bodyValueForKey:AWMessageKMoreInfo];
}

- (NSString *)owner {
    if ([self.moreInfo objectForKey:AWMessageKOwner]) { // 可能 key: AWMessageKOwner 是不存在的。
        return self.moreInfo[AWMessageKOwner];
    }
    return nil;
    
}

- (NSString *)description {
    return [NSString stringWithFormat:@"%@ <%@: %p %@>",
            [super description],
            self.class,
            self,
            @{ @"noticeOperator": _noticeOperator ?: @""}];
}

- (NSString *)debugDescription {
    return [NSString stringWithFormat:@"%@ <%@: %p %@>",
            [super description],
            self.class,
            self,
            @{ @"noticeOperator": _noticeOperator ?: @""}];
}

@end
